<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>创建角色</title>
</head>
<link type="text/css" rel="stylesheet" th:href="@{~/bootstrap-3.3.7/css/bootstrap.css}"/>
<script type="text/javascript" th:src="@{~/bootstrap-3.3.7/js/jquery.js}"></script>
<script type="text/javascript" th:src="@{~/bootstrap-3.3.7/js/bootstrap.js}"></script>
<body>
<div th:align="center">
    <h3 th:text="创建角色"></h3>
</div>

<div class="row">
    <div class="form-group">
        <label for="inputEmail3" class="col-sm-2 control-label">角色名称</label>
        <div class="col-sm-10">
            <input type="text" class="form-control" th:name="name" id="inputEmail3" placeholder="请输入英文">
        </div>
    </div>
</div>
<div class="row">
    <div class="form-group">
        <label for="inputPassword3" class="col-sm-2 control-label">角色介绍</label>
        <div class="col-sm-10">
            <input type="text" class="form-control" th:name="description" id="inputPassword3" placeholder="请输入中文">
        </div>
    </div>
</div>

<div class="row">
    <div class="form-group">
        <label for="inputPassword11" class="col-sm-2 control-label">添加权限</label>
        <div class="col-sm-10">
            <span th:each="r,stat : ${resources}" id="inputPassword11">
                <span th:if="${r.opened == 2}">
                    <h5 th:text="${r.description}" style="color: red">xx</h5>
                </span>
                <span th:if="${r.opened != 2}">
                    <input type="checkbox" th:value="${r.id}" th:name="id" th:text="${r.description}"
                           th:checked="${r.flag}"/>
                </span>
            </span>
        </div>
    </div>

</div>


<script>

    function add() {
        var ids = "";
        $("[name='id']:checked").map(function () {
            ids += " ," + $(this).val();
        });
        ids = ids.substring(2);

        var description = $("[name='description']").val();
        var name = $("[name='name']").val();
        $.post(
            "/role/addRole",
            {
                sid: ids,
                name : name,
                description : description
            },
            function (data) {
                if (data == 1) {
                    alert("成功");
                    location.href = "/role/listRole";
                } else {
                    alert("失败")
                }
            },
            "json"
        );

    }

</script>

<div class="row" style="margin-top: 50px">
    <div class="form-group">
        <div class="col-sm-offset-2 col-sm-10">
            <a href="javascript:void(0)" class="btn btn-success"
               th:onclick="'javascript:add()'">添加资源</a>
        </div>
    </div>
</div>
</body>
</html>